import { PureComponent } from "react"
import { Cart1, Cart2 } from "../../components/04Cart"

export default class Cpn extends PureComponent {
  constructor() {
    super()
    this.state = {
      token: localStorage.getItem("isLoginHOCToken")
    }
  }

  setToken() {
    localStorage.setItem("isLoginHOCToken", "TRUE")
    console.log(this, "setToken")
    this.setState({
      token: localStorage.getItem("isLoginHOCToken")
    })
    // 不建议使用this.forceUpdate()
  }

  removeToken() {
    localStorage.removeItem("isLoginHOCToken")
    console.log(this, "removeToken")
    this.setState({
      token: localStorage.getItem("isLoginHOCToken")
    })
    // 不建议使用this.forceUpdate()
  }

  render() {
    const { token } = this.state
    const { setToken, removeToken } = this
    return (
      <div>
        <Cart1
          token={token}
          setToken={setToken.bind(this)}
          removeToken={removeToken.bind(this)}
        />
        <Cart2
          token={token}
          setToken={setToken.bind(this)}
          removeToken={removeToken.bind(this)}
        />
      </div>
    )
  }
}
